//
//  HomeQuestionCompleteInfoViewController.m
//  ZJControlsClass
//
//  Created by mac on 2024/12/2.
//

#import "HomeQuestionCompleteInfoViewController.h"
#import "HomeAvailableNetworking.h"
#import "HomeQuestionCompleteInfoTableViewCell.h"
#import "HomeQuestionModel.h"




@interface HomeQuestionCompleteInfoViewController ()<UITableViewDelegate,UITableViewDataSource>


@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) NSMutableArray * dataSource;


@property (nonatomic,strong) HomeProcessDetailNetworking * manager;



@end

@implementation HomeQuestionCompleteInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.title = @"考试结果";
    
    self.view.backgroundColor = COLOR_RGB(50, 113, 237);

    [self loadNet];
    [self setUpUI];
    
}


-(void)setUpUI{
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self.view);
    }];
    
}




-(void)loadNet{
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = @"正在加载...";
    [hud removeFromSuperViewOnHide];
    
    [self.manager dispatchTaskWithParam:@{@"examId":self.examId} completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        [hud hideAnimated:YES];
        if (responseObject && [responseObject[@"code"] intValue] == 200){
            
            [self.dataSource  addObjectsFromArray:[HomeQuestionModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]]];
            [self.tableView reloadData];
            
        }else{
            [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:nil];
            return;
        }
        
    }];
    
    
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HomeQuestionCompleteInfoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeQuestionCompleteInfoTableViewCell"];
    if (!cell){
        cell = [[HomeQuestionCompleteInfoTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"HomeQuestionCompleteInfoTableViewCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.dataSource[indexPath.row];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    HomeQuestionModel * model = self.dataSource[indexPath.row];
//    // 高度自适应
//    return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[HomeQuestionCompleteInfoTableViewCell class] contentViewWidth:SCREEN_WIDTH - ALIGN_WIDTH_PT(30)];
    
    return ALIGN_HEIGHT_PT(420);
    
}



#pragma mark -- 懒加载
-(UITableView *)tableView{
    if (!_tableView){
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor clearColor];
    }
    return _tableView;
}

-(NSMutableArray *)dataSource{
    if (!_dataSource){
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

-(HomeProcessDetailNetworking *)manager{
    if (!_manager){
        _manager = [HomeProcessDetailNetworking new];
    }
    return _manager;
}




@end
